package com.library.service;

import com.library.entity.UserInfo;
import com.library.controller.RCException;
import com.library.mapper.UserInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    public void add(UserInfo oaDepartment) {
        UserInfo userInfo = new UserInfo();
        userInfo.setName(oaDepartment.getName());
        List<UserInfo> userInfos = this.userInfoMapper.selectByQuery(userInfo);
        if(!userInfos.isEmpty()){
            throw new RCException("员工名称重复了");
        }
        // 密码默认
        oaDepartment.setPassword("123123");
        this.userInfoMapper.insertSelective(oaDepartment);
    }

    public void delete(UserInfo oaDepartment) {
        this.userInfoMapper.deleteByPrimaryKey(oaDepartment.getId());
    }

    public UserInfo detail(UserInfo oaDepartment) {
        UserInfo userInfo = this.userInfoMapper.selectByPrimaryKey(oaDepartment.getId());
        return userInfo;
    }

    public void update(UserInfo userInfo) {
        int i = this.userInfoMapper.updateByPrimaryKey(userInfo);
    }

    public List<UserInfo> list(UserInfo userInfo) {
        List<UserInfo> userInfos = this.userInfoMapper.selectByQuery(userInfo);
        return userInfos;
    }
}
